//
//  EditTableViewController.m
//  NaviAndTable
//
//  Created by student on 16/3/7.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "EditTableViewController.h"
#import "BIDPresident.h"
@interface EditTableViewController ()
@property (nonatomic,strong) NSMutableArray *list;
@end

@implementation EditTableViewController

- (NSMutableArray *)list
{
    if (_list == nil)
    {
        _list = [NSMutableArray array];
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Presidents" ofType:@"plist"];
        NSData *data = [NSData dataWithContentsOfFile:path];
        
        NSKeyedUnarchiver *unArch = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
        NSArray *arr = [unArch decodeObjectForKey:@"presidents"];
//        [_list addObject:arr]; // 错误,这是将数组作为一个对象，加入到list中
        
        
        [_list addObjectsFromArray:arr];// 将数组中的每个元素，加入到list当中
        
    }
    return _list;
}




- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.list.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    BIDPresident *pre = self.list[indexPath.row];
    cell.textLabel.text = pre.name;
    
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@-%@",pre.fromYear,pre.toYear];
    return cell;
   
}







@end
